import { reqProfileList } from '@/api';
import { reqProfile2List } from '@/api';
import { reqAcademies } from '@/api';
import { reqOffices } from '@/api';
import { reqItemList } from '@/api';
import { reqOfficeItemList } from '@/api';
import { reqAllItemList } from '@/api';
import { reqAllOfficeItemList } from '@/api';

const state = {
  academiesList: [],
  academies: {},
  officesList: [],
  offices: {},
  itemList: [],
  officeItemList: [],
  allOfficeItemList: [],
};
const mutations = {
  GETACADEMIESLIST(state, academiesList) {
    state.academiesList = academiesList;
  },
  GETOFFICESLIST(state, officesList) {
    state.officesList = officesList;
  },
  GETOFFICES(state, offices) {
    state.offices = offices;
  },
  GETACADEMIES(state, academies) {
    state.academies = academies;
  },
  GETITEMLIST(state, itemList) {
    state.itemList = itemList;
  },
  GETOFFICEITEMLIST(state, officeItemList) {
    state.officeItemList = officeItemList;
  },
  GETALLITEMLIST(state, allItemList) {
    state.allItemList = allItemList;
  },
  GETALLOFFICEITEMLIST(state, allOfficeItemList) {
    state.allOfficeItemList = allOfficeItemList;
  },
};
const actions = {
  async getAcademiesList({ commit }) {
    let result = await reqProfileList();

    if (result.code == 1) {
      commit('GETACADEMIESLIST', result.data);
    }
  },
  
  // 根据书院id获取
  async getAcademies({ commit }, id) {
    let result = await reqAcademies(id);
    if (result.code == 1) {
      commit('GETACADEMIES', result.data);
    }
  },
  // 根据官职id获取
  async getOffices({ commit }, id) {
    let result = await reqOffices(id);
    if (result.code == 1) {
      commit('GETOFFICES', result.data);
    }
  },
  async getOfficesList({ commit }) {
    let result = await reqProfile2List();

    if (result.code == 1) {
      commit('GETOFFICESLIST', result.data);
    }
  },
  async getItemList({ commit }, id) {
    let result = await reqItemList(id);
    if (result.code == 1) {
      commit('GETITEMLIST', result.data);
    }
  },
  async getOfficeItemList({ commit }, id) {
    let result = await reqOfficeItemList(id);
    if (result.code == 1) {
      commit('GETOFFICEITEMLIST', result.data);
    }
  },
  async getAllItemList({ commit }, id) {
    let result = await reqAllItemList(id);

    if (result.code == 1) {
      commit('GETALLITEMLIST', result.data);
    }
  },
  async getAllOfficeItemList({ commit }, id) {
    let result = await reqAllOfficeItemList(id);

    if (result.code == 1) {
      commit('GETALLOFFICEITEMLIST', result.data);
    }
  },
};
const getters = {};

export default {
  state,
  mutations,
  actions,
  getters,
};
